﻿//***********************************************************************
// Assembly         : NMortgage.UI
// Author           : Mike
// Created          : 04-07-2012
//
// Last Modified By : Mike
// Last Modified On : 04-07-2012
// Description      : 
//
// Copyright        : (c) . All rights reserved.
//***********************************************************************
namespace NMortgage.UI.Model
{
    using System;
    using System.Text;

    using FluentValidation;
    using FluentValidation.Results;
    using System.Diagnostics.CodeAnalysis;

    public static class ValidationHelper
    {
        #region Methods

        public static string GetError(ValidationResult result)
        {
            var validationErrors = new StringBuilder();
            foreach (var validationFailure in result.Errors)
            {
                validationErrors.Append(validationFailure.ErrorMessage);
                validationErrors.Append(Environment.NewLine);
            }
            return validationErrors.ToString();
        }

        public static ValidationResult Validate<TEntity, KValidator>(TEntity entity)
            where TEntity : class
            where KValidator : IValidator<TEntity>, new()
        {
            if (entity == null) { return null; }

            IValidator<TEntity> validator = new KValidator();
            return validator.Validate(entity);
        }

        #endregion Methods
    }
}